package com.explorer.ider.bootguide.itembean;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.Nullable;

public class UserModel {

    public String userName;
    public String userDateOfBirth;
    @Nullable
    public String userImageUrl;
    public String userGender;
    public String isRegistered;

    public final static String SHARE_PREFERENCES_FILENAME = "SHARE_PREFERENCES_FILENAME";
    public final static String SHARE_PREFERENCES_EMAIL = "SHARE_PREFERENCES_EMAIL";
    public final static String SHARE_PREFERENCES_USER_IMG = "SHARE_PREFERENCES_USER_IMG_URL";
    public final static String SHARE_PREFERENCES_USER_STATUS = "SHARE_PREFERENCES_USER_STATUS";


    public final static String SHARE_PREFERENCES_GCM_TOKEN = "SHARE_PREFERENCES_GCM_TOKEN";


    private static UserModel mInstance = null;

    public static UserModel getInstance() {
        if (mInstance == null) {
            mInstance = new UserModel();
        }
        return mInstance;
    }

    private UserModel() {
    }

    public String getEmail(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHARE_PREFERENCES_EMAIL, null);
    }

    public void setEmail(String email, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(SHARE_PREFERENCES_EMAIL, email);
        editor.commit();
    }

    public String getWmac(Context context) {
        //  return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHARE_PREFERENCES_GCM_TOKEN, null);
    }

    public void setWmac(String gcmToken, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(SHARE_PREFERENCES_GCM_TOKEN, gcmToken);
        editor.commit();
    }

    // Generated Getters and Setters
    public String getUserName() {
        return userName;
    }


    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDateOfBirth() {
        return userDateOfBirth;
    }

    public void setDateOfBirth(String dateOfBirth) {
        this.userDateOfBirth = dateOfBirth;
    }

    public void removeUserData() {
        mInstance = null;
    }

//    public String getUserImageUrl() {
//        return userImageUrl;
//    }

    public String getUserImageUrl(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHARE_PREFERENCES_USER_IMG, null);
    }

    public void setUserImageUrl(String userImageUrl, Context context) {
//        this.userImageUrl = userImageUrl;
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(SHARE_PREFERENCES_USER_IMG, userImageUrl);
        editor.commit();
    }

    @Nullable
    public String getUserGender() {
        return userGender;
    }

    public void setUserGender(String userGender) {
        this.userGender = userGender;
    }


    public String getIsRegistered(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHARE_PREFERENCES_USER_STATUS, null);
    }

    public void setIsRegistered(String isRegistered, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(UserModel.SHARE_PREFERENCES_FILENAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(SHARE_PREFERENCES_USER_STATUS, isRegistered);
        editor.commit();
    }

}